﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Sitecore.Data.Items;
using System.Data;
using Workflow.Alerts.DAL;
using Workflow.Alerts.Interfaces.ProfileSettings;

namespace Workflow.Alerts
{
    public class NetworkOperatorListPresenter : Presenter
    {
        #region members
        private readonly NetworkOperatorDAL model;
        private readonly INetworkOperatorListView view;
        #endregion

        #region constructor
        public NetworkOperatorListPresenter(INetworkOperatorListView _view)
            : this(_view, null)
        { }

        public NetworkOperatorListPresenter(INetworkOperatorListView _view, ISessionProvider session)
            : base(_view, session)
        {
            view = base.GetView<INetworkOperatorListView>();
            view.OnPageLoad += view_OnLoad;
            model = new NetworkOperatorDAL();
        }

        #endregion

        #region private methods

        private void view_OnLoad()
        {   
            var filter = new WorkflowFilter
            {
                MunicipalityId = CurrentUser.TypeId//CurrentUser.MunicipalityId
            };

            var filterSql = new WorkflowFilterSql(filter);

            DataTable operators = model.GetNetworkOperatorList(filterSql);

            view.NetworkOperators = operators;
        }

        #endregion
    }
}
